
var picUrl = 'img/pic.png'
var num1=0;
var vm =new Vue({
    el:'#app2',
    data:{
        arr:[
            {pic:picUrl,title:'秋刀鱼/斤',price:13,count:1},
            {pic:picUrl,title:'牛蹄筋/斤', price:14,count:2},
            {pic:picUrl,title:'烤山药/斤',price:15,count:3},
        ],
        quan:['32减12','70减35','100减45','150减60']
    },
    methods:{
        add(item){
           item.count++;
        },
        sub(item){
            if( item.count > 1 )item.count--;
        },
        clean(){
            this.arr = [];
        },
        sub(item){
            if(item.count>1)item.count--;
        }
    },
    computed:{
        totalCount(){
            console.log('计算属性: totalCount 执行了');
            var sum = 0;
            this.arr.forEach((item)=>{
                sum += item.count;
            })
            return sum;
        },
        totalPrice: {
            get(){ 
                var sum = 0;
                this.arr.forEach((item)=>{
                    sum += item.count * item.price;
                })
                return sum;
            },
            set(){ 
                console.log( '给totalPrice设置值' );
            }
        }
    }
})
